<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>
		
<script type="text/javascript">
	$(function(){
		$("body").css({visibility:"visible"});
		//提交表单
		
		$("#select_use").change(
			function() {
				var selected = $("#select_use").val();
				if(selected==1){
					$("#customer_td").show();
				}else{
					$("#customer_td").hide();
				}
			}		
		)
		
		 $('#save').click(function(){
			 //若是改版类型为员工自用改版，则客户id为申请者id
			 if($('#select_use').val()==0){
					$('[name=cVBuyerId]').val($('[name=cVProposerId]').val());
			}
			var flag=true;
			$('#sform :input').each(function(){
				//alert('name='+this.name+'===value='+this.value);
				if(this.name){
					if(!this.value){
						flag=false;
					}
				}
				
			});
				// 校验
				if(flag){
					// 1 、获得form 数据
					var params = $('#sform').serialize();
					// 2、将数据发送给服务器 
					$.post("${pageContext.request.contextPath}/page.saveChangeVersion.ashx", params , function(data){
						//alert(data)
						
						if(data.status == "1"){
							// 成功
							$.messager.alert('消息','操作成功 ','info', function(){
								location.href="${pageContext.request.contextPath}/page.rulerversion.ashx"
							});
							
						
						}else if(data.status==("notbelong")){
								$.messager.alert('消息',data.RSN+'不属于当前客户！','info');
						}else if(data.status==("nobuyer")){
							$.messager.alert('消息',data.RSN+'没有填写客户信息，请联系管理员修改','info');
						}else{
							data = new String(data);
							if(data.charAt(0)=='<'){
								$.messager.alert('消息','没有权限','info');
							}else{
								$.messager.alert('消息','操作失败','info');
							}
						}
						
							
					});
				}else{
					$.messager.alert("提示", "请检查输入项是否有遗漏未输入","warnning");
				}
				
			});	
	});
	
	function getQueryString(name) { 
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); 
		var r = window.location.search.substr(1).match(reg); 
		if (r != null) return unescape(r[2]); return null; 
	} 
	function formatterVersion(value){
		if(value==0){
			return "基础版";
		}else if(value==1){
			return "高定版";
		}else if(value==2){
			return "团装版";
		}else if(value==3){
			return "体验版";
		}
	}
	$(document).ready(function(){
		//$('#opcode_1').focus();
		var length = getQueryString("length")
		$("#opnumber").val(length);
		
		//动态生成表单
    	for(i=0;i<length-1;i++){
    		
    	
           var _len = $("#tab tr").length;        
           $("#tab").append("<tr><td>产品条码:</td>"
           						+"<td name='opcode_"+_len+"' id='opcode_"+_len+"'></td>"
           						+"<input type='hidden' name='opcodeinput_"+_len+"' id='opcodeinput_"+_len+"'/>"
           						+"<td>原版本:</td>"
           						+"<td name='opversion_"+_len+"' id='opversion_"+_len+"' ></td>"            
          						+"<td>新版本:</td>"
          						+"<td><select name='copversion_"+_len+"' id='copversion_"+_len+"' ><option value='-1'></option><option value ='1'>&nbsp;高定版&nbsp;</option><option value='2'>&nbsp;团装版&nbsp;</option></select></td></tr>");            
/*            						+"<td><select name='copversion_"+_len+"' id='copversion_"+_len+"' ><option value='-1'></option><option value ='0'>&nbsp;基础版&nbsp;</option><option value ='1'>&nbsp;高定版&nbsp;</option><option value='2'>&nbsp;团装版&nbsp;</option><option value='3'>&nbsp;体验版&nbsp;</option></select></td></tr>");            

 */
    	}
		
		
		var sns = new  String(getQueryString("sns"));
		var snsArr = sns.split(",");
		for(var i = 0; i<snsArr.length;i++){
			var temp = new String(snsArr[i]);
			var snAndVersion = temp.split(":");
			$("#opcode_"+(i+1)).html(snAndVersion[0]);
			$("#opcodeinput_"+(i+1)).val(snAndVersion[0]);
			$("#opversion_"+(i+1)).html(formatterVersion(snAndVersion[1]));
		}
	}); 
	
	window.onload=function(){
		//基本信息格式化
		$("#oDealTime").html(formatterDate($("#oDealTime").html()));
		$("#oITime").html(formatterDate($("#oITime").html()));
		$("#oIsDone").html($("#oIsDone").html()=="false"?"未处理":"已处理");
	}
	function formatterDate(value){
		if(value==''||null==value){
			return '';
		}
		var now = new Date(parseInt(value) * 1000);  
		var year=now.getYear()+1900; 
		var month=now.getMonth()+1; 
		var date=now.getDate(); 
		var hour=now.getHours(); 
		var minute=now.getMinutes();
		minute= (minute > 9) ? minute=minute : minute='0'+minute;
		//var second=now.getSeconds(); 
		return year+"-"+month+"-"+date+" "+hour+":"+minute; 
	}
</script>	
</head>
<body class="easyui-layout" style="visibility:hidden;">
	<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
		<div class="datagrid-toolbar">
			<a id="save" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
			
		</div>
	</div>
    <div region="center" style="overflow:auto;padding:5px;" border="false">
          <form id="sform">  
		      
    
     
         <table class="table-edit"  width="95%" align="center">
           		<tr class="title"><td colspan="10">处理信息</td></tr>
           		
	           <tr>
	           <td>申请人:</td>
						<td><input class="easyui-combobox"   editable="false",
									required="true"
									name="cVProposerId"
									data-options="
											url:'${pageContext.request.contextPath}/page.kuguanListAll.ashx?refreshcache=new Date().getTime()',
											method:'get',
											valueField:'sId',
											textField:'sName',
											panelHeight:'300'
						"></td>
				<td>经手人:</td>
						<td><input class="easyui-combobox"   editable="false",
						
						
									required="true"
									name="cVStorekeeperId"
									data-options="
											url:'${pageContext.request.contextPath}/page.kuguanListAll.ashx?refreshcache=new Date().getTime()',
											method:'get',
											valueField:'sId',
											textField:'sName',
											panelHeight:'300'
						"></td>
						
						<td>改版原因：</td>
						<td>
							<select name="cVType" id="select_use"  >
								   <option></option>
								   <option value ="0">员工自用改版</option>
								  <option value="1">销售提货改版</option>
							</select> 
							
							
						</td>
					
					
					 
					
						
					<td>
					<label id="customer_td" hidden="hidden" >客户名称:
						<input class="easyui-combobox"   editable="false",
									name="cVBuyerId"
									id="cVBuyerId"
									data-options="
											url:'${pageContext.request.contextPath}/page.buyerListAll.ashx?refreshcache=new Date().getTime()',
											method:'get',
											valueField:'bId',
											textField:'bName',
											panelHeight:'200'
						"></label></td>
						
					
				
					<tr>	
					<td>备注:</td>
						<td colspan="3"> <input id="cVRemark" name="cVRemark" type="text"   style="width:40%;" /></td>
						
						
						</tr>
						
			</table>
			
				<table id="tab" class="table-edit"  width="95%" align="center">
				<input type="hidden" name="opnumber" id="opnumber"/>
				<tr class="title"><td colspan="6">产品信息</td></tr>
				 <tr>	<td>产品条码:</td>
						<td name="opcode_1" id="opcode_1"></td>
						<input type="hidden" name="opcodeinput_1" id="opcodeinput_1"/>
	           			<td>原版本:</td>
					 <td name="opversion_1" id="opversion_1">
					</td>
					
					<td>新版本:</td>
					 <td>
						<select name="copversion_1" id="copversion_1">
						  <option></option>
						  <option value ="1">&nbsp;高定版&nbsp;</option>
						  <option value="2">&nbsp;团装版&nbsp;</option>
						</select>
					</td>
				</tr>
	           
	         </table>  
         </form>  
	</div>
</body>
</html>